<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <link rel="stylesheet" type="text/css" href="./css/font-awesome.min.css" />
    <script type="text/javascript" src="./script/jquery.min.js"></script>
    <link class="theme" rel="stylesheet" type="text/css" href="./css/color/blue.css" />
    <script type="text/javascript" src="./script/doT.min.js"></script>

</head>

<body>
    <!-- <div class="list-t">
        <img src="images/cover_logo.png">
        <span>中共佳木斯市委组织部</span>
    </div> -->

    <div id="two">
    </div>

    <script type='text/template' id='templateTwo'>
        <div class="classify">
            <ul class="classify-t">

                {{ for(var prop in it[0]) { }}
                <li>
                    <h3>{{=it[0][prop].DName}}</h3>
                    <ul>
                        {{ for(var proped in it[1]) { }} {{? it[0][prop].ID == it[1][proped].PID}}
                        <li onclick="click_in({{=it[1][proped].ID}})">{{=it[1][proped].DName}}</li>
                        {{?}} {{ } }}
                    </ul>
                </li>
                {{ } }}

            </ul>
        </div>
    </script>




</body>
<script type="text/javascript" src="./script/api.js"></script>
<script type="text/javascript" src="./script/aui-tab.js"></script>
<script type="text/javascript">
    function click_in(index) {

    //   var h;
    //   if(window.orientation==180||window.orientation==0){
    //         // alert("竖屏状态！")
    //         h = api.winHeight - 50;
    //    }
    // if(window.orientation==90||window.orientation==-90){
    //         // alert("横屏状态！")
    //         h = api.winHeight -50;
    //     }

        api.openFrame({
            name: 'classify-imgNew',
            url: './classify-imgNew.html',
            rect: {
                x: 0,
                y: 0,
                w: 'auto',
                h: api.winHeight -50
            },
            pageParam: {
                id: index,
            },
            bounces: false,
            bgColor: 'rgba(0,0,0,0)',
            vScrollBarEnabled: true,
            hScrollBarEnabled: true
        });
        api.showProgress({
            title: '努力加载中...',
            text: '先喝杯茶...',
            modal: false
        });
    }

    // 折叠菜单
    $(function() {

    });

    function nav(n) {
        api.openFrame({
            name: 'classify',
            url: './classify-nav' + n + '.html',
            rect: {
                x: 0,
                y: 0,
                w: 'auto',
                h: api.winHeight - 50

            },
            pageParam: {
                name: 'test'
            },
            bounces: false,
            bgColor: 'rgba(0,0,0,0)',
            vScrollBarEnabled: false,
            hScrollBarEnabled: false,

        });


    }

    // tab切换
    apiready = function() {
        var color = $api.getStorage('color');
        $(".theme").attr("href", color);



        api.parseTapmode();
        var tempId;
        var db = api.require('db');
        db.selectSql({
            name: 'data',
            sql: "SELECT * FROM base_level WHERE PID = 0"
        }, function(ret, err) {
            if (ret.status) {
                tempId = ret.data[0].ID;
                title = ret.data;
                // var dotFn = doT.template(template.innerHTML);
                // var html = dotFn(ret.data);
                // var list = $api.byId('list');
                // $api.html(list, html);
                //分类
                twoLevel(tempId);
            } else {
                alert(JSON.stringify(err));
            }
        });
    }

    function twoLevel(id) {

        var sql2 = 'SELECT *,base_level.DName AS name FROM base_level,base_depart WHERE base_level.PID = ' + id + ' AND base_depart.PID = base_level.ID';
        var sql = 'SELECT * FROM base_level WHERE PID =' + id
        var innerData = new Array();
        var db = api.require('db');
        db.selectSql({
            name: 'data',
            sql: sql
        }, function(ret, err) {
            if (ret.status) {
                innerData[0] = ret.data;
                //二次查询
                db.selectSql({
                    name: 'data',
                    sql: sql2
                }, function(ret, err) {
                    if (ret.status) {
                        innerData[1] = ret.data;
                        var dotFn = doT.template(templateTwo.innerHTML);
                        var html = dotFn(innerData);
                        var list = $api.byId('two');
                        $api.html(list, html);
                        $(".classify-t h3").on("click", function() {
                            $(".classify-t ul").slideUp();
                            $(this).next(".classify-t ul").stop().slideToggle(300);
                        });
                    }
                });

                //分界
            } else {
                alert(JSON.stringify(err));
            }
        });

    }


        function reloadIndex() {
          var color = $api.getStorage('color');
          $(".theme").attr("href", color);
        }



    var tab = new auiTab({
        element: document.getElementById("tab"),
    }, function(ret) {
        console.log(ret)
    });
</script>

</html>
